Replace whitespaces with an underscore¶
S.replace(” “, “_”)
Replace whitespaces with an underscore and vice versa.
import re
S = 'Python Exercises'
S = S.replace(" ", "_")
print(S)
S = S.replace("_", " ")
print(S)
Output:
Python_Exercises
Python Exercises